package com.autumn.log.service.mq;

import com.autumn.log.LogEventData;
import com.autumn.log.service.domain.LogBiz;
import com.autumn.mq.event.EventHandlerConfigure;
import com.autumn.mq.event.EventMessage;
import com.autumn.mq.event.IEventHandler;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@EventHandlerConfigure(name = LogEventData.EVENT_NAME, concurrentConsumers = 10)
public class LogEventHandler implements IEventHandler<LogEventData> {

	private final static Log logger = LogFactory.getLog(LogEventHandler.class);

	@Override
	public boolean errorAutoRepeatSend() {
		return false;
	}

	@Override
	public Log getLogger() {
		return logger;
	}

	@Autowired
	private LogBiz service;

	@Override
	public void onHandler(EventMessage<LogEventData> message) {
		try {
			service.save(message.getData());
		} catch (Exception ex) {
			ex.printStackTrace(System.err);
		}
	}

}
